<%--
 *  File:    ZylOrgPriceInfo.jsp
 *  @Author: yuelongma 
 *  Date:    2011/01/27
 *
 *  Copyright (C) 2000 - 2011 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java"%>
<%@ page import="java.util.*"%>
<%@ page import="org.apache.log4j.Category"%>

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom"%>
<%
  //init param
  Category cat = Category.getInstance("jsp.ZylOrgPriceInfo"); 
  String privilegeCode = "10101";
  String strModuleName = "OGM";
  String contextPath = request.getContextPath();
%>
<%@ include file="/inc/PageDefault.inc"%>
<%@ include file="/inc/CatchError.inc" %>

<html>
<head>
<title>DTKeyPerson</title>
<PageFlow:CheckPageFlow pageName="p_zylorgpriceinfo" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%= contextPath%>/css/<%= strLanguageCode %>/main.css"	type="text/css">
<script language="JavaScript" src="<%= contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%= contextPath%>/js/ScriptLib.js"></script>

<%@ include file="/inc/SummaryDivision.inc"%>
<%
  Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
  if(totalsummary == null)
  {
	  totalsummary = new Vector();
  }          
%>

<%
String strDisplayFlag="";
if(request.getParameter("displayflag")!=null)
{
  strDisplayFlag=request.getParameter("displayflag");
}
%>
<script>
function page_delete()
{
	if(isNullChecked(cform.orgprodpriceids))
	{
	  alert("<%=message.getMessageDesc("PLEASE_SELECT")%>");
	  return;
	}
  	document.cform.actionname.value = "delete";
  	cform.target = "_self";
  	//isRunning = true;
  	//document.cform.submit();
  	 __submitData('orgprice',true);
     }

function page_add()
{	
	if(!checkForm(document.cform))
 			return;
     document.cform.actionname.value = "add";
     cform.target = "_self";
    // isRunning = true;
     //document.cform.submit();
       __submitData('orgprice',true);
  }

function checkenddate(startdate,enddate){
	var endvalue,startvalue;
	if(startdate==''){
    	startvalue = dateCheck(enddate.parentNode.previousSibling.firstChild.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');
		endvalue = dateCheck(enddate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');
    }else if(enddate==''){
		startvalue = dateCheck(startdate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');
    	endvalue = dateCheck(startdate.parentNode.nextSibling.firstChild.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');
    }
    if(endvalue<0 || startvalue<0)
    {
       alert("<%= message.getMessageDesc("VALUE_MUST_BE_DATE",label.getLabelName("L_Date",false) )%>");
       return;
    }
    if(endvalue!=''&&endvalue<startvalue) {
       alert("<%= message.getMessageDesc("STARTDATE_CAN_NOT_LATE_THAN_ENDDATE")%>");
       return;
   }
}

function page_save()
{
   document.cform.actionname.value = "save" ;
   cform.target = "_self";
   // isRunning = true;
   //document.cform.submit();
   __submitData('orgprice',true);
  }

function page_summary(actionvalue,orderbyname)
 {	 
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
 
  editform.action = "ZylOrgPriceInfo.jsp?<%= OvalTools.randomURL() %>";
  
  editform.target = "_self";
  isRunning = true;
  editform.submit();
 }

function page_back(){
	window.location.href="OrgSummary.jsp?<%= OvalTools.randomURL() %>&summaryidentify=distributor&languagecode=<%=strLanguageCode%>";
}

function page_selectProd() {
	var status = "height=400, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
	var url = "<%=contextPath%>/phap/phap.datp/masterdata/kdm/ProductSelect.jsp?o_thread=" + Math.random();
	if (typeof popwindow != 'undefined') popwindow.close();
	popwindow = window.open(url, "newwindow", status);
}

function page_setproduct(id,umcode,prodcode,prodname){
	document.cform.prodid.value=id;
	document.cform.prodname.value=prodname;
	page_setstartdate();
}

function page_setstartdate(){
	var datahandler = new DataHandler();
	datahandler.add_params("prodid" , cform.prodid.value , "Integer");
	datahandler.add_params("orgid" , cform.orgid.value , "Integer");
	//datahandler.getResult("startdate","document.cform.startdate");
	datahandler.getResultFromHashMap("startdatehash","startdate","document.cform.tempstartdate");
	datahandler.add_job("j_zylselectenddate");
	datahandler.add_function("checkstartdate()");
	datahandler.runDataHandler();
	
}

function checkstartdate(){
	var startdate = cform.tempstartdate.value;
	if(startdate!="null"){
		document.cform.startdate.value = startdate;
		document.cform.startdate.onfocus = "";
	}else{
		document.cform.startdate.value = "";
		document.cform.startdate.onfocus = function(){c.show(this,'cform.startdate','yyyy-MM-dd')};
	}
}
</script>

</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
   <table width="100%" cellspacing="0" cellpadding="0">
	   <form name="cform" method="post" action="<%= contextPath%>/Dispatcher" target="_self" id="orgprice">
		<input type="hidden" name="pagename" value="p_zylorgpriceinfo">
		<input type="hidden" name="numrows" value="<%=totalsummary.size() %>">
		<custom:hidden property="actionname"></custom:hidden>
		<custom:hidden property="orgid"></custom:hidden>
		<custom:hidden property="tempstartdate"/>
	     <tr>
		<td valign="top">
		<table width="100%" cellspacing="0" cellpadding="0">
			<tr>
				<td class="summary_top"></td>
			</tr>
		</table>
		<table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
			<tr>
				<tr class="deepblue-left">
					<td width="25">&nbsp;</td>
					<td class="title_center">&nbsp;<%= label.getLabelName("L_Product") %><font size="3" color="red">*</font></td>
					<td class="title_center">&nbsp;<%= label.getLabelName("L_StartTime") %><font size="3" color="red">*</font></td>
					<td class="title_center">&nbsp;<%= label.getLabelName("L_EndTime") %><font size="3" color="red">*</font></td>
					<td class="title_center">&nbsp;<%= label.getLabelName("L_ExWorksPrice") %></td>
					<td class="title_center">&nbsp;<%= label.getLabelName("L_PurPrice") %></td>
					<td class="title_center">&nbsp;<%= label.getLabelName("L_SellingPrice") %></td>
					<td class="title_center">&nbsp;<%= label.getLabelName("L_AssessmentPrice") %></td>
				</tr>
				<span id="olddata">
				<%
        		int i = 0;
     			String strClassType = new String("");
     			String startdate = "startdate";
     			String enddate = "enddate";
            	%>
				<logic:iterate id="onerow" collection="<%=totalsummary %>" indexId="idx">
				<% 
				HashMap priceInfo = (HashMap)pageContext.getAttribute("onerow");
				if(priceInfo == null)
					priceInfo = new HashMap();
		        if(i%2 == 1)
		        {
		    	    strClassType = "td-listrom";
		        }else{                    
		     	    strClassType = "none";
		        }		        
		        startdate = "c.show(this,'cform.startdate"+i+"','yyyy-MM-dd')";
		        enddate = "c.show(this,'cform.enddate"+i+"','yyyy-MM-dd')";
		        i++;        
     		    %>
				<tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'" class="<%=JspHelper.filterNull( strClassType )%>">
					<td>
						<%if(!(strDisplayFlag).equals("view")){%>
						<input type="checkbox" name="orgprodpriceids" value="<%=JspHelper.filterNull( priceInfo.get("orgprodpriceid"))%>">
						<custom:hidden property="orgprodpriceid" name="onerow" colIndex="<%=idx %>"></custom:hidden>
						<%}else{ %>
						&nbsp;
						<%} %>
					</td>
					<td>
						<custom:write property="prodname" name="onerow"/>
						<%--<custom:hidden property="prodid" name="onerow"/>--%>
					</td>
					<td>
						<%if(!(strDisplayFlag).equals("view")){%>
						<custom:text property="startdate" onblur="checkenddate(this,'')" name="onerow" readonly="true" colIndex="<%=idx %>" dataType="date" dataFormatName="dateformat" command="notnull" label="L_StartTime" onfocus="<%=startdate %>"/>
						<%}else{ %>
						<custom:text property="startdate" name="onerow"/>
						<%} %>
					</td>
					<td>
						<%if(!(strDisplayFlag).equals("view")){%>
						<custom:text property="enddate" onblur="checkenddate('',this)" name="onerow" readonly="true" colIndex="<%=idx %>" dataType="date" dataFormatName="dateformat" command="notnull" label="L_EndTime" onfocus="<%=enddate %>"/>
						<%}else{ %>
						<custom:text property="enddate" name="onerow"/>
						<%} %>
					</td>
					<td><custom:text property="factoryprice" colIndex="<%=idx %>" name="onerow" /></td>
					<td><custom:text property="purchaseprice" colIndex="<%=idx %>" name="onerow" /></td>
					<td><custom:text property="salesprice" colIndex="<%=idx %>" name="onerow" /></td>
					<td><custom:text property="checkprice" colIndex="<%=idx %>" name="onerow" /></td>
				</tr>
				</logic:iterate>
				</span>

				<% //--------------------------------------  flipping page --%>
				<%if(!(strDisplayFlag).equals("view")){%>
				<span id="newdata">
				<tr>
					<td>&nbsp;</td>
					<td>
						<custom:text property="prodname" readonly="true" onchange="page_setstartdate();" command="notnull" label="L_Product" />
						<a onclick="javascript:page_selectProd();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0" /></a>
						<custom:hidden property="prodid" />
					</td>
					<td>
						<custom:text property="startdate" onblur="checkenddate(this,'')" readonly="true" dataType="date" dataFormatName="dateformat" command="notnull" label="L_StartTime" onfocus="c.show(this,'cform.startdate','yyyy-MM-dd')"/>
					</td>
					<td>
						<custom:text property="enddate" onblur="checkenddate('',this)" readonly="true" dataType="date" dataFormatName="dateformat" command="notnull" label="L_EndTime" onfocus="c.show(this,'cform.enddate','yyyy-MM-dd')"/>
					</td>
					<td><custom:text property="factoryprice" /></td>
					<td><custom:text property="purchaseprice" /></td>
					<td><custom:text property="salesprice" /></td>
					<td><custom:text property="checkprice" /></td>
					<custom:hidden property="status" value="41"/>
				</tr>
				</span>
				<%}%>
			<%--<%@include file="/inc/SummaryAction.inc" %>--%>
		</table>
		<table width="100%" cellspacing="0" cellpadding="0">
			<tr>
				<td class="summary_top"></td>
			</tr>
			<tr>
				<td class="td_center">
				<%if(!(strDisplayFlag).equals("view")){%>
				<a onclick="page_add();"><custom:button type="2" label="L_Add" imgsrc="add.gif" border="0" style="width:60" /></a>
				<a onclick="page_save();"><custom:button type="2" label="L_Save" imgsrc="save.gif" border="0" style="width:60" /></a>
				<a onclick="page_delete();"><custom:button type="2" label="L_Delete" imgsrc="delete.gif" border="0" style="width:60"/></a>
				<%}%>
				<a onclick="page_back();"><custom:button type="2" label="L_Back" imgsrc="back.gif" border="0" style="width:60"/></a>
				</td>
			</tr>
		</table>
		</td>
	</tr>
	</form>
</table>
</body>
</html>


